import axios from 'axios';
import router from 'vue-router';

import {
    Message
} from 'element-ui';

//创建axios实例
const request = axios.create({
    baseURL: process.env.BASE_URL,
});

request.interceptors.response.use((response) => {
    let res = response.data;
    if (res.status === 0) {
        return res.data;
    } else if (res.status === 2) {
       window.location.href= process.env.BASE_URL + '#/login';
       return Promise.reject(res);
    } else {
        Message.warning(res.msg);
        return Promise.reject(res);
    }
}, (error) => {
    let res = error.response;
    Message.error(res.data.message);
    return Promise.reject(res.data.message);
});


export default request;